﻿using System;
using System.Data;
using System.Text;
using System.IO;
using System.Collections;
using iTextSharp.text.html.simpleparser;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using iTextSharp.text;
using System.Data.SqlClient;
using System.Globalization;
using System.Web.UI;
using System.Web;
using iTextSharp.text.pdf;




public partial class Main_ServiceInvoice_SalesInvoiceView : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = "";
    DataTable DTMain = new DataTable();
    DataTable dtGetFullDetail = new DataTable();
    NumberFormatInfo nfi = new CultureInfo("hi-IN", false).NumberFormat;
    int rowcount = 0;
    string lblInformation = "";


    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCustomData();
        }
    }
    protected void BindCustomData()
    {
        DataTable DTMain = DU.getdatausingprocedure("USP_IVC_GetSaleInvoiceMain");
        grdDisplay.DataSource = DTMain;
        grdDisplay.DataBind();
    }
    protected void grdDisplay_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdDisplay.PageIndex = e.NewPageIndex;
        BindCustomData();
    }
    private void PrepareGridViewForExport(Control gv)
    {
        HiddenField hidControl = new HiddenField();
        for (int i = 0; i < gv.Controls.Count; i++)
        {
            if (gv.Controls[i].GetType() == typeof(HiddenField))
            {
                gv.Controls.Remove(gv.Controls[i]);
            }
            if (gv.Controls[i].HasControls())
            {
                PrepareGridViewForExport(gv.Controls[i]);
            }
        }
    }
    protected void grdDisplay_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "editsi")
        {
            string[] strTemp = e.CommandArgument.ToString().Split(',');
            string invoiceid = strTemp[0];
            string tranid = strTemp[1];
            Response.Redirect("SaleInvoiceEdit.aspx?INVOICEID=" + invoiceid + "&TRANID=" + tranid);
        }
        else if (e.CommandName.ToString() == "printpdf")
        {
           // string[] ids = e.CommandArgument.ToString().Split(',');
           // string invoice = ids[0].ToString();
           // string tran = ids[1].ToString();
           // BindCompDetails();
           // BindFullDetail(invoice, tran);
           // BindDetails(invoice, tran, hidddltext.Value.ToString());

           //Document document = new Document(PageSize.A3, 10f, 10f, 10f, 0f);
         
           // try
           // {
           //     StringWriter sw = new StringWriter();

           //     HtmlTextWriter htw = new HtmlTextWriter(sw);
           //     PrepareGridViewForExport(pnlpdf);
           //     pnlpdf.RenderControl(htw);
           //     string strDataBody = "<html><head></head><body>" + htw.InnerWriter.ToString() + "</body></html>";
           //     iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();

           //     PdfWriter.GetInstance(document, Response.OutputStream);

           //     document.Open();

           //     ArrayList objects;
           //     document.NewPage();
           //     string strHTMLpath = Server.MapPath("~/Main/ServiceInvoice/TestPDF/SaleInvoicePrint.html");
           //     FileInfo t = new FileInfo(strHTMLpath);
           //     StreamWriter Tex = t.CreateText();
           //     Tex.WriteLine(strDataBody);
           //     Tex.Close();
           //     Tex.Dispose();
           //     StreamReader fp = new StreamReader(t.OpenRead());
           //     // StreamReader fp = new StreamReader(File.Open(strHTMLpath, FileMode.Open, FileAccess.Read, FileShare.Read));
           //     string strReadHtml = fp.ReadToEnd();
           //     fp.Close();
           //     fp.Dispose();
           //     Paragraph p2 = new Paragraph();
           //     objects = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(strReadHtml), styles);

           //     for (int k = 0; k < objects.Count; k++)
           //     {
           //        p2.Add((iTextSharp.text.IElement)objects[k]);
           //     }
           //     p2.Font = FontFactory.GetFont("Arial", 5);
           //     document.Add(p2);
           //     document.Close();
           //     Response.Write(document);

           //     Response.ContentType = "application/pdf";
           //     Response.AddHeader("content-disposition", "attachment;filename=SaleInvoice.pdf");
           //     Response.Cache.SetCacheability(HttpCacheability.NoCache);
           //     Response.End();
           // }
           // catch (Exception ex)
           // {
           //     throw ex;
           // }
        }
    }

    protected void grdDisplay_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string strInvoiceId = grdDisplay.DataKeys[e.Row.RowIndex].Values["INVOICEID"].ToString();
            string strTranId = grdDisplay.DataKeys[e.Row.RowIndex].Values["TRANID"].ToString();
            HyperLink hyperView = (HyperLink)e.Row.FindControl("hyperView");
            LinkButton lkbtnpdf = (LinkButton)e.Row.FindControl("lkbtnpdf");
            DropDownList ddlChoice = (DropDownList)e.Row.FindControl("ddlChoice");
            hyperView.Attributes.Add("onclick", "return OpenInvoiceWindow('" + ddlChoice.ClientID + "','" + strInvoiceId + "','" + strTranId + "','view');");
            //lkbtnpdf.Attributes.Add("onclick", "return OpenInvoiceWindow('" + ddlChoice.ClientID + "','" + strInvoiceId + "','" + strTranId + "','pdf');");
        }
    }
    protected void custPager_PageChanged(object sender, CustomPageChangeArgs e)
    {
        grdDisplay.PageSize = e.CurrentPageSize;
        grdDisplay.PageIndex = e.CurrentPageNumber;
        BindCustomData();
    }
    protected void grdDisplay_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onclick", "document.getElementById('hidrowindex').value = this.rowIndex;");
        if (e.Row.RowType != DataControlRowType.Pager)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridview_alternate'");

            }
            else if (e.Row.RowState == DataControlRowState.Normal)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridviewitem'");

            }
        }
    }
    protected void grdDisplay_SelectedIndexChanged(object sender, EventArgs e)
    {
        //e.Row.Attributes.Add("onclick", "document.getElementById('hidrowindex').value = this.rowIndex;");
    }
    protected void BindCompDetails()
    {

        DataTable dtCompDtl = DU.getdatausingprocedure("usp_get_company_details");
        string strCompDtl = "<b>Supplier</b><br />";
        string strCompNoDtl = "";
        if (dtCompDtl.Rows.Count > 0)
        {
            if (dtCompDtl.Rows[0]["compname"].ToString() != string.Empty)
            {
                strCompDtl += dtCompDtl.Rows[0]["compname"].ToString() + "<br />";
                lblInvoiceFor.Text = dtCompDtl.Rows[0]["compname"].ToString();
            }
            if (dtCompDtl.Rows[0]["add1"].ToString() != string.Empty)
            {
                strCompDtl += dtCompDtl.Rows[0]["add1"].ToString();
            }
            if (dtCompDtl.Rows[0]["add2"].ToString() != string.Empty)
            {
                strCompDtl += " " + dtCompDtl.Rows[0]["add2"].ToString() + ",<br />";
            }
            if (dtCompDtl.Rows[0]["add3"].ToString() != string.Empty)
            {
                strCompDtl += dtCompDtl.Rows[0]["add3"].ToString();
            }
            if (dtCompDtl.Rows[0]["add4"].ToString() != string.Empty)
            {
                strCompDtl += " " + dtCompDtl.Rows[0]["add4"].ToString() + ",<br />";
            }
            if (dtCompDtl.Rows[0]["place"].ToString() != string.Empty)
            {
                strCompDtl += dtCompDtl.Rows[0]["place"].ToString();
            }
            if (dtCompDtl.Rows[0]["pincode"].ToString() != string.Empty)
            {
                strCompDtl += "-" + dtCompDtl.Rows[0]["pincode"].ToString() + "<br />";
            }
            if (dtCompDtl.Rows[0]["state"].ToString() != string.Empty)
            {
                strCompDtl += dtCompDtl.Rows[0]["state"].ToString();
            }
            if (dtCompDtl.Rows[0]["country"].ToString() != string.Empty)
            {
                strCompDtl += " " + dtCompDtl.Rows[0]["country"].ToString() + ".<br />";
            }
            if (dtCompDtl.Rows[0]["Phone"].ToString() != string.Empty)
            {
                strCompDtl += "Phone-" + dtCompDtl.Rows[0]["Phone"].ToString() + "<br />";
            }
            if (dtCompDtl.Rows[0]["Email"].ToString() != string.Empty)
            {
                strCompDtl += "Email-" + dtCompDtl.Rows[0]["Email"].ToString() + "<br />";
            }
            if (dtCompDtl.Rows[0]["LogoUrl"].ToString() != string.Empty)
            {
                imgLogo.ImageUrl = dtCompDtl.Rows[0]["LogoUrl"].ToString();
                imgLogo.Visible = true;
            }
            else
            {
                imgLogo.Visible = false;
            }
            if (dtCompDtl.Rows[0]["pan"].ToString() != string.Empty)
            {
                lblPanNo.Text = dtCompDtl.Rows[0]["pan"].ToString();
                lblCompPAN.Text = "Company's PAN";
            }
            else
            {
                lblPanNo.Text = "";
                lblCompPAN.Text = "";
            }
            if (dtCompDtl.Rows[0]["vatno"].ToString() != string.Empty)
            {
                lblVATTIN.Text = dtCompDtl.Rows[0]["vatno"].ToString();
                lblCompVat.Text = "Company's VAT TIN";
            }
            else
            {
                lblCompVat.Text = "";
                lblVATTIN.Text = "";
            }
            if (dtCompDtl.Rows[0]["sertno"].ToString() != string.Empty)
            {
                lblServiceTaxNo.Text = dtCompDtl.Rows[0]["sertno"].ToString();
                lblCompServ.Text = "Company's Service Tax No.";
            }
            else
            {
                lblServiceTaxNo.Text = "";
                lblCompServ.Text = "";
            }
        }
        lblSupplier.Text = strCompDtl;
    }
    protected void BindDetails(string invoice, string tran, string ddltext)
    {
        if (invoice != string.Empty && tran != string.Empty && ddltext != string.Empty)
        {
            SqlParameter[] sqlparam = {
                                              new SqlParameter("@invoiceid",invoice),
                                              new SqlParameter("@Tranid",tran)
                                          };
            lblViewType.Text = "(" + ddltext + ")";
            DataTable DTMain = DU.getdatausingprocedure("USP_IVC_GetSaleInvoiceDetails", sqlparam);
            string invoiceto = "";

            if (DTMain.Rows.Count > 0)
            {
                if (DTMain.Rows[0]["billno"].ToString() != string.Empty)
                {
                    lblBillNo.Text = DTMain.Rows[0]["billno"].ToString();
                }
                if (DTMain.Rows[0]["refno"].ToString() != string.Empty)
                {
                    lblRefNo.Text = DTMain.Rows[0]["refno"].ToString();
                }
                if (DTMain.Rows[0]["voudate"].ToString() != string.Empty)
                {
                    lblDate.Text = string.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(DTMain.Rows[0]["voudate"].ToString()));
                }
                if (DTMain.Rows[0]["totalamt"].ToString() != string.Empty)
                {
                    nfi.CurrencySymbol = "";
                    lblGrandTotal.Text = Convert.ToDouble(DTMain.Rows[0]["totalamt"].ToString()).ToString("C", nfi);
                }
                if (DTMain.Rows[0]["customer"].ToString() != string.Empty)
                {
                    invoiceto += DTMain.Rows[0]["customer"].ToString() + "<br />";
                }
                if (DTMain.Rows[0]["Address1"].ToString() != string.Empty)
                {
                    invoiceto += DTMain.Rows[0]["Address1"].ToString();
                }
                if (DTMain.Rows[0]["Address2"].ToString() != string.Empty)
                {
                    invoiceto += " " + DTMain.Rows[0]["Address2"].ToString() + ",<br />";
                }
                if (DTMain.Rows[0]["Address3"].ToString() != string.Empty)
                {
                    invoiceto += DTMain.Rows[0]["Address3"].ToString();
                }
                if (DTMain.Rows[0]["place"].ToString() != string.Empty)
                {
                    invoiceto += " " + DTMain.Rows[0]["place"].ToString();
                }
                if (DTMain.Rows[0]["Pincode"].ToString() != string.Empty)
                {
                    invoiceto += "-" + DTMain.Rows[0]["Pincode"].ToString() + ",<br />";
                }
                if (DTMain.Rows[0]["state"].ToString() != string.Empty)
                {
                    invoiceto += DTMain.Rows[0]["state"].ToString();
                }
                if (DTMain.Rows[0]["Country"].ToString() != string.Empty)
                {
                    invoiceto += " " + DTMain.Rows[0]["Country"].ToString() + "<br />";
                }
                if (DTMain.Rows[0]["EMAIL"].ToString() != string.Empty)
                {
                    invoiceto += "Email-" + DTMain.Rows[0]["EMAIL"].ToString() + "<br />";
                }
                if (DTMain.Rows[0]["PHONE"].ToString() != string.Empty)
                {
                    invoiceto += "Phone-" + DTMain.Rows[0]["PHONE"].ToString();
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["FIRMNAMEADDRYN"].ToString()) != true)
                {
                    lblSupplier.Text = "";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["INFORMATIONYN"].ToString()))
                {
                    lblInformation = DTMain.Rows[0]["INFORMATION"].ToString();
                }
                else
                {
                    lblInformation = "Amount in words-";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["STREGNOYN"].ToString()) != true)
                {
                    lblServiceTaxNo.Text = "";
                    lblCompServ.Text = "";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["CAPTIONYN"].ToString()) != true)
                {
                    lblCaption.Text = "SALE INVOICE";
                }
                else
                {
                    lblCaption.Text = DTMain.Rows[0]["BILLCAPTION"].ToString();
                }
                if (DTMain.Rows[0]["GTInwords"].ToString() != string.Empty)
                {
                    lblAmountInWords.Text = lblInformation + DTMain.Rows[0]["GTInwords"].ToString();
                }
                if (DTMain.Rows[0]["PREPAREDBY"].ToString() != string.Empty)
                {
                    lblpreparedby.Text = DTMain.Rows[0]["PREPAREDBY"].ToString() + "<br />";
                    lblpreparedbyHead.Text = "Prepared By";
                }
                else
                {
                    lblpreparedbyHead.Text = "";
                    lblpreparedby.Text = "";
                }
                if (DTMain.Rows[0]["CHECKEDBY"].ToString() != string.Empty)
                {
                    lblcheckedby.Text = DTMain.Rows[0]["CHECKEDBY"].ToString() + "<br />";
                    lblcheckedbyHead.Text = "Checked By";
                }
                else
                {
                    lblcheckedbyHead.Text = "";
                    lblcheckedby.Text = "";
                }
                if (DTMain.Rows[0]["SERVICEDBY"].ToString() != string.Empty)
                {
                    lblservicedby.Text = DTMain.Rows[0]["SERVICEDBY"].ToString() + "<br />";
                    lblservicedbyHead.Text = "Serviced By";
                }
                else
                {
                    lblservicedbyHead.Text = "";
                    lblservicedby.Text = "";
                }
                if (DTMain.Rows[0]["Narration"].ToString() != string.Empty)
                {
                    lblNarration.Text = DTMain.Rows[0]["Narration"].ToString() + "<br />";
                    lblNarrHead.Text = "Narration : ";
                }
                else
                {
                    lblNarrHead.Text = "";
                    lblNarration.Text = "";
                }
                if (DTMain.Rows[0]["comments"].ToString() != string.Empty)
                {
                    lblRemarks.Text = DTMain.Rows[0]["comments"].ToString() + "<br />";
                    lblRemarksHead.Text = "Remarks : ";
                }
                else
                {
                    lblRemarksHead.Text = "";
                    lblRemarks.Text = "";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["logoyn"].ToString()) != true)
                {
                    imgLogo.Visible = false;
                }
                else
                {
                    imgLogo.Visible = true;
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["PANYN"].ToString()) != true)
                {
                    lblPanNo.Text = "";
                    lblCompPAN.Text = "";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["CHECKEDBYYN"].ToString()) != true)
                {
                    lblcheckedbyHead.Text = "";
                    lblcheckedby.Text = "";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["SERVICEDBYYN"].ToString()) != true)
                {
                    lblservicedbyHead.Text = "";
                    lblservicedby.Text = "";
                }
                if (Convert.ToBoolean(DTMain.Rows[0]["PREPAREDBYYN"].ToString()) != true)
                {
                    lblpreparedbyHead.Text = "";
                    lblpreparedby.Text = "";
                }
                lblInvoiceTo.Text = invoiceto;
            }
        }


    }
    protected void BindFullDetail(string invoiceid, string tranid)
    {

        if (invoiceid != string.Empty && tranid != string.Empty)
        {
            SqlParameter[] sqlparam = {
                                              new SqlParameter("@invoiceid",invoiceid)
                                           
                                          };
            dtGetFullDetail = DU.getdatausingprocedure("USP_IVC_GetSaleInvoice_FullDetail", sqlparam);
            if (dtGetFullDetail.Rows.Count > 0)
            {
                AddNewRow();
            }
        }

    }
    protected void AddNewRow()
    {
        double pecessSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(PECessAmt)", ""));
        double hecessSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(HECessAmt)", ""));
        double stSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(servicetaxamt)", ""));
        double disSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(discount)", ""));
        double servchrgSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(servicechargeamt)", ""));
        double qtySum = Convert.ToDouble(dtGetFullDetail.Compute("sum(Unit)", ""));
        double rateSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(Rate)", ""));
        double grossSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(GrossAmt)", ""));
        double totalSum = Convert.ToDouble(dtGetFullDetail.Compute("sum(totalamt)", ""));
        int countUOM = Convert.ToInt32(dtGetFullDetail.Compute("count(UOM)", "UOM <>''"));
        int countNatureServ = Convert.ToInt32(dtGetFullDetail.Compute("count(service)", "service<>''"));

        nfi.CurrencySymbol = "";
        int tempcounter = Convert.ToInt32(dtGetFullDetail.Rows.Count);
        if (dtGetFullDetail.Rows.Count > 0)
        {
            for (int i = 0; i < tempcounter; i++)
            {
                rowcount++;

                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell0 = new HtmlTableCell();
                cell0.Align = "left";
                cell0.Style.Add("border", "1px solid black");
                cell0.Style.Add("border-left", "0px white");
                cell0.BorderColor = "#d6d3ce";

                Label lblSNo = new Label();
                lblSNo.ID = "lblSno" + rowcount.ToString();
                lblSNo.Text = (i + 1).ToString();

                cell0.Controls.Add(lblSNo);

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "left";
                cell1.Style.Add("border", "1px solid black");
                cell1.BorderColor = "#d6d3ce";

                Label lblNatureofService = new Label();
                lblNatureofService.ID = "lblNatureofService" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["service"].ToString() != string.Empty)
                {
                    lblNatureofService.Text = dtGetFullDetail.Rows[i]["service"].ToString();
                }

                cell1.Controls.Add(lblNatureofService);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "left";
                cell2.Style.Add("border", "1px solid black");
                cell2.BorderColor = "#d6d3ce";

                Label lblUom = new Label();
                lblUom.ID = "lblUom" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["UOM"].ToString() != string.Empty)
                {
                    lblUom.Text = dtGetFullDetail.Rows[i]["UOM"].ToString();
                }
                cell2.Controls.Add(lblUom);


                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "right";
                cell3.Style.Add("border", "1px solid black");
                cell3.BorderColor = "#d6d3ce";

                Label lblQty = new Label();
                lblQty.ID = "lblQty" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["Unit"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["Unit"].ToString())>0)
                {
                    lblQty.Text = string.Format("{0:0.00}", Convert.ToDouble(dtGetFullDetail.Rows[i]["Unit"].ToString()));

                }

                cell3.Controls.Add(lblQty);

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "right";
                cell4.Style.Add("border", "1px solid black");
                cell4.BorderColor = "#d6d3ce";

                Label lblRate = new Label();
                lblRate.ID = "lblRate" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["Rate"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["Rate"].ToString())>0)
                {
                    lblRate.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["Rate"].ToString()).ToString("C", nfi);

                }

                cell4.Controls.Add(lblRate);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "right";
                cell5.Style.Add("border", "1px solid black");
                cell5.BorderColor = "#d6d3ce";

                Label lblGrossAmt = new Label();
                lblGrossAmt.ID = "lblGrossAmt" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["GrossAmt"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["GrossAmt"].ToString())>0 )
                {
                    lblGrossAmt.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["GrossAmt"].ToString()).ToString("C", nfi);

                }

                cell5.Controls.Add(lblGrossAmt);

                HtmlTableCell cell6 = new HtmlTableCell();
                cell6.Align = "right";
                cell6.Style.Add("border", "1px solid black");
                cell6.BorderColor = "#d6d3ce";

                Label lblSt = new Label();
                lblSt.ID = "lblSt" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["servicetaxamt"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["servicetaxamt"].ToString())>0 )
                {
                    lblSt.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["servicetaxamt"].ToString()).ToString("C", nfi);

                }

                cell6.Controls.Add(lblSt);

                HtmlTableCell cell7 = new HtmlTableCell();
                cell7.Align = "right";
                cell7.Style.Add("border", "1px solid black");
                cell7.BorderColor = "#d6d3ce";

                Label lblHE = new Label();
                lblHE.ID = "lblHE" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["HECessAmt"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["HECessAmt"].ToString())>0)
                {
                    lblHE.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["HECessAmt"].ToString()).ToString("C", nfi);

                }

                cell7.Controls.Add(lblHE);

                HtmlTableCell cell8 = new HtmlTableCell();
                cell8.Align = "right";
                cell8.Style.Add("border", "1px solid black");

                cell8.BorderColor = "#d6d3ce";

                Label lblPE = new Label();
                lblPE.ID = "lblPE" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["PECessAmt"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["PECessAmt"].ToString())>0)
                {
                    lblPE.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["PECessAmt"].ToString()).ToString("C", nfi);

                }

                cell8.Controls.Add(lblPE);

                HtmlTableCell cell9 = new HtmlTableCell();
                cell9.Align = "right";
                cell9.Style.Add("border", "1px solid black");
                cell9.BorderColor = "#d6d3ce";

                Label lblsrvchrg = new Label();
                lblsrvchrg.ID = "lblsrvchrg" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["servicechargeamt"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["servicechargeamt"].ToString())>0)
                {
                    lblsrvchrg.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["servicechargeamt"].ToString()).ToString("C", nfi);

                }

                cell9.Controls.Add(lblsrvchrg);

                HtmlTableCell cell10 = new HtmlTableCell();
                cell10.Align = "right";
                cell10.Style.Add("border", "1px solid black");
                cell10.BorderColor = "#d6d3ce";

                Label lblDis = new Label();
                lblDis.ID = "lblDis" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["discount"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["discount"].ToString())>0)
                {
                    lblDis.Text = Convert.ToDouble(dtGetFullDetail.Rows[i]["discount"].ToString()).ToString("C", nfi);

                }

                cell10.Controls.Add(lblDis);

                HtmlTableCell cell11 = new HtmlTableCell();
                cell11.Align = "right";
                cell11.Style.Add("border", "1px solid black");
                cell11.Style.Add("border-right", "0px white");
                cell11.BorderColor = "#d6d3ce";

                Label lblTtlAmt = new Label();
                lblTtlAmt.ID = "lblTtlAmt" + rowcount.ToString();
                if (dtGetFullDetail.Rows[i]["totalamt"].ToString() != string.Empty)// && Convert.ToDouble(dtGetFullDetail.Rows[i]["totalamt"].ToString())>0)
                {
                    lblTtlAmt.Text = Convert.ToDouble(Convert.ToDouble(Convert.ToDouble(dtGetFullDetail.Rows[i]["GrossAmt"].ToString()) + Convert.ToDouble(dtGetFullDetail.Rows[i]["servicetaxamt"].ToString()) + Convert.ToDouble(dtGetFullDetail.Rows[i]["HECessAmt"].ToString()) + Convert.ToDouble(dtGetFullDetail.Rows[i]["PECessAmt"].ToString()) + Convert.ToDouble(dtGetFullDetail.Rows[i]["servicechargeamt"].ToString()) - Convert.ToDouble(dtGetFullDetail.Rows[i]["discount"].ToString()))).ToString("C", nfi); //string.Format("{0:0.00}", Convert.ToDouble(dtGetFullDetail.Rows[i]["totalamt"].ToString())));

                }

                cell11.Controls.Add(lblTtlAmt);

                row.Cells.Add(cell0);
                if (countNatureServ > 0)
                {
                    row.Cells.Add(cell1);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdNature")).Style.Add("display", "none");
                }
                if (countUOM > 0)
                {
                    row.Cells.Add(cell2);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdUnit")).Style.Add("display", "none");
                }
                if (qtySum > 0)
                {
                    row.Cells.Add(cell3);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdQty")).Style.Add("display", "none");
                }
                if (rateSum > 0)
                {
                    row.Cells.Add(cell4);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdRate")).Style.Add("display", "none");
                }
                if (grossSum > 0)
                {
                    row.Cells.Add(cell5);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdGrossAmt")).Style.Add("display", "none");
                }
                if (stSum > 0)
                {
                    row.Cells.Add(cell6);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdST")).Style.Add("display", "none");
                }
                if (hecessSum > 0)
                {
                    row.Cells.Add(cell7);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdHE")).Style.Add("display", "none");
                }
                if (pecessSum > 0)
                {
                    row.Cells.Add(cell8);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdPE")).Style.Add("display", "none");
                }
                if (servchrgSum > 0)
                {
                    row.Cells.Add(cell9);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdServ")).Style.Add("display", "none");
                }
                if (disSum > 0)
                {
                    row.Cells.Add(cell10);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdDis")).Style.Add("display", "none");
                }
                if (totalSum > 0)
                {
                    row.Cells.Add(cell11);
                }
                else
                {
                    ((HtmlTableCell)tblDetail.Rows[0].FindControl("tdTotal")).Style.Add("display", "none");
                }
                tblDetail.Rows.Add(row);
                //hidControlCounter.Value = rowcount.ToString();
            }
        }
        //int rslt = 20 - tempcounter;
        //if (rslt > 0)
        //{
        //    for (int j = 0; j <= rslt; j++)
        //    {
        //        HtmlTableRow row1 = new HtmlTableRow();

        //        HtmlTableCell cel0 = new HtmlTableCell();
        //        cel0.Align = "left";
        //        cel0.InnerHtml = "&nbsp;";
        //        cel0.BorderColor = "#ffffff";

        //        HtmlTableCell cel1 = new HtmlTableCell();
        //        cel1.Align = "left";
        //        cel1.InnerHtml = "&nbsp;";
        //        cel1.BorderColor = "#ffffff";

        //        HtmlTableCell cel2 = new HtmlTableCell();
        //        cel2.Align = "left";
        //        cel2.InnerHtml = "&nbsp;";
        //        cel2.BorderColor = "#ffffff";

        //        HtmlTableCell cel3 = new HtmlTableCell();
        //        cel3.Align = "right";
        //        cel3.InnerHtml = "&nbsp;";
        //        cel3.BorderColor = "#ffffff";

        //        HtmlTableCell cel4 = new HtmlTableCell();
        //        cel4.Align = "right";
        //        cel4.InnerHtml = "&nbsp;";
        //        cel4.BorderColor = "#ffffff";

        //        HtmlTableCell cel5 = new HtmlTableCell();
        //        cel5.Align = "right";
        //        cel5.InnerHtml = "&nbsp;";
        //        cel5.BorderColor = "#ffffff";

        //        HtmlTableCell cel6 = new HtmlTableCell();
        //        cel6.Align = "right";
        //        cel6.InnerHtml = "&nbsp;";
        //        cel6.BorderColor = "#ffffff";

        //        HtmlTableCell cel7 = new HtmlTableCell();
        //        cel7.Align = "right";
        //        cel7.InnerHtml = "&nbsp;";
        //        cel7.BorderColor = "#ffffff";

        //        HtmlTableCell cel8 = new HtmlTableCell();
        //        cel8.Align = "right";
        //        cel8.InnerHtml = "&nbsp;";
        //        cel8.BorderColor = "#ffffff";

        //        HtmlTableCell cel9 = new HtmlTableCell();
        //        cel9.Align = "right";
        //        cel9.InnerHtml = "&nbsp;";
        //        cel9.BorderColor = "#ffffff";

        //        HtmlTableCell cel10 = new HtmlTableCell();
        //        cel10.Align = "right";
        //        cel10.InnerHtml = "&nbsp;";
        //        cel10.BorderColor = "#ffffff";

        //        HtmlTableCell cel11 = new HtmlTableCell();
        //        cel11.Align = "right";
        //        cel11.InnerHtml = "&nbsp;";
        //        cel11.BorderColor = "#ffffff";

        //        row1.Cells.Add(cel0);
        //        if (countNatureServ > 0)
        //        {
        //            row1.Cells.Add(cel1);
        //        }
        //        if (countUOM > 0)
        //        {
        //            row1.Cells.Add(cel2);
        //        }
        //        if (qtySum > 0)
        //        {
        //            row1.Cells.Add(cel3);
        //        }
        //        if (rateSum > 0)
        //        {
        //            row1.Cells.Add(cel4);
        //        }
        //        if (grossSum > 0)
        //        {
        //            row1.Cells.Add(cel5);
        //        }
        //        if (stSum > 0)
        //        {
        //            row1.Cells.Add(cel6);
        //        }
        //        if (hecessSum > 0)
        //        {
        //            row1.Cells.Add(cel7);
        //        }
        //        if (pecessSum > 0)
        //        {
        //            row1.Cells.Add(cel8);
        //        }
        //        if (servchrgSum > 0)
        //        {
        //            row1.Cells.Add(cel9);
        //        }
        //        if (disSum > 0)
        //        {
        //            row1.Cells.Add(cel10);
        //        }
        //        if (totalSum > 0)
        //        {
        //            row1.Cells.Add(cel11);
        //        }
        //        tblDetail.Rows.Add(row1);
        //    }

        //}
    }
}
